package leet.ku._38;

public class Solution {
	public String countAndSay(int n) {
		StringBuilder sb = new StringBuilder("1");
		for (int i = 1; i < n; i++) {
			StringBuilder _sb = new StringBuilder();
			int count = 1;
			char last = sb.charAt(0);
			for (int j = 1; j < sb.length(); j++)
				if (sb.charAt(j) != last) {
					_sb.append(count).append(last);
					count = 1;
					last = sb.charAt(j);
				} else
					count++;
			_sb.append(count).append(last);
			sb = _sb;
		}
		return sb.toString();
	}
}
